package lianxi5.Runtime;

public class text1 {
    public static void main(String[] args) {
        //availableProcessors 获取cpu线程数
        Runtime r = Runtime.getRuntime();
        System.out.println("CPU线程数: " + r.availableProcessors());

        //exit 停止虚拟机
        //r.exit(0);

        //maxMemory 获取最大内存
        long l = r.maxMemory();
        System.out.println("最大内存: " + l / 1024 / 1024 + "MB");

        //totalMemory 获取总内存
        long l1 = r.totalMemory();
        System.out.println("总内存: " + l1 / 1024 / 1024 + "MB");

        //freeMemory 获取空闲内存
        long l2 = r.freeMemory();
        System.out.println("空闲内存: " + l2 / 1024 / 1024 + "MB");

        //exec 运行cmd命令
        try {
            Process p = r.exec("shutdown -a");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
